<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- 引入主题样式 -->
<link href="themes/gray/easyui.css" rel="stylesheet">
<!-- 引入图标的样式 -->
<link href="themes/icon.css" rel="stylesheet">
<!-- 先引入jquery -->
<script type="text/javascript" src="js/jquery-1.7.2.js"></script>
<!-- 引入easyui -->
<script type="text/javascript" src="js/jquery-1.7.2.js"></script>
<script type="text/javascript" src="js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="js/easyui-lang-zh_CN.js"></script>
<script type="text/javascript">  
$(function() {  
           $('#dg').datagrid({
           url:"userset",
           title:'用户信息',
           rownumbers : true,
  	       striped : true,
  		   pagination : true,
  		   pageSize : 18,
  		   pageList : [ 18, 26, 36 ],
  		   toolbar: [{
				iconCls: 'icon-no',
				text:'删除用户',
				handler: function(){
					var checked = $('#dg').datagrid('getChecked');
					if(checked.length==0){
						$.messager.alert('提示信息', '请选中要删除的用户', 'info', function() {
							
						});
					}else{
						var unames = new Array();
						var msg = "<br /><br />您确认要删除以下用户信息吗?<br />";
						$.each(checked,function(i,n){
							unames[i] = n.uname;
							msg += n.uname+"&emsp;&emsp;&emsp;&emsp;"+n.rname+"<hr />";
						})
						$.messager.confirm('消息提示', msg, function(r){
							if (r){
							    $.ajax({
							    	url:'deleteUserMsg',//删除选中的用户信息
							    	type:'post',
							    	data:{
							    		unames:unames
							    	},
							    	dataType:'text',
							    	success:function(data){
							    		var data = eval('('+data+')');
							    		if (data.success) {
											$.messager.alert('提示信息', data.msg, 'info', function() {
												$('#dg').datagrid('reload');
											});
										} else {
											$.messager.alert('提示信息', data.msg, 'info', function() {
												$('#dg').datagrid('reload');
											});
										}
							    	}
							    });
							}
						});
					}
				}
			},'-',{
				iconCls: 'icon-add',
				text:'打印用户',
				handler: function(){
					$('#printDg').datagrid('reload');
					$('#printWin').window('open');
				}
			}],
           columns:
            [[
              {field:'ck',title:'选择行',checkbox:true},  
              {field:'uid',title:'序号',hidden:true},
              {field:'uname',title:'用户名',width:'47%'},
              {field:'upsw',title:'密码',width:'25%',hidden:true},
              {field:'rname',title:'角色',width:'47%'},
            	 ]],
            });
             $('#btn').linkbutton({ 
                iconCls: 'icon-ok',
                text:"点击更改角色",
                onClick:function(){
                	var rows = $('#dg').datagrid('getSelections');
                	if(rows.length==0)
                		{
                		$.messager.confirm('确认','请先选中对象！')
                		}
                	else if(rows.length==1)
                		{
                		$('#win').window('open'); 
                		$('#quxiao').bind('click',function(){
           				 $('#win').window('close');
           				 
           			 });
                		 $('#xiugai').bind('click', function(){   
                			 
                			 var rows  = $('#dg').datagrid('getSelections');
								var uids = [];
								for (var i = 0; i < rows.length; i++) {
									uids.push(rows[i].uid);
								}
								var rid = $('#cc').combobox('getValue');
                 		      $.ajax({
               					url:'cuser',
               					type:'post',
               					dataType:'text',
               					data:{'rid':rid,
               						  'uids':uids},
               					success:function(data){
               						$('#printDg').datagrid('reload');
                 						$('#win').window('close');
                 						$('#dg').datagrid('reload');
                 						
               						
               						
               					}
                             	});
                		      
                		    }); 
                		}
                	else
                		{ 
                		$.messager.confirm('确认','是否进行批量操作！',function(r){    
                		    if (r){    
                		    	$('#win').window('open');
                		    	$('#quxiao').bind('click',function(){
                		    		 $('#win').window('close'); 
                   				 
                   			 })
                		    	$('#xiugai').bind('click', function(){
								var rows  = $('#dg').datagrid('getSelections');
								var uids = [];
								for (var i = 0; i < rows.length; i++) {
									uids.push(rows[i].uid);
								}
								var rid = $('#cc').combobox('getValue');
                    		      $.ajax({
                  					url:'cuser',
                  					type:'post',
                  					dataType:'text',
                  					data:{'rid':rid,
                  						  'uids':uids},
                  					success:function(data){
                  						$('#printDg').datagrid('reload');
                    						$('#win').window('close');
                    						$('#dg').datagrid('reload');
                    						
                  						
                  						
                  					}
                                	});
								//
                		    	})
                		    }    
                		}); 
                		}
                	
                }
             
                });
             $('#win').window({    
                width:300,    
                height:200,    
                modal:true,
                minimizable:false,
                closable:false,
                resizable:false,
            }); 
            $('#win').window('close'); 
            //角色下拉框
            $('#cc').combobox({    
                url:'role',    
                valueField:'id',    
                textField:'text',
                width:250,    
                height:30
            });  
            
           //配置打印用户窗口
    		$('#printWin').window({
    			width : 600,
    			height : 400,
    			title : '批量导入用户',
    			collapsible : false,
    			minimizable : false,
    			maximizable : false,
    			closable : false,
    			draggable : false,
    			resizable : false,
    		});
    		$('#printWin').window('close');
    		
    		//配置打印预览表格
    		$('#printDg').datagrid({    
    		    url:'allUserMsg',//加载全部用户信息请求
    		    title:'用户信息',
    		    striped : true,
    			pagination : true,
    			rownumbers : true,
    			height:580,
    			pageSize : 100,
    			pageList : [ 100, 200, 300 ],
    			toolbar: [{
    				iconCls: 'icon-add',
    				text:'打印用户',
    				handler: function(){
    					var checked = $('#printDg').datagrid('getChecked');
    					if(checked.length==0){
    						$.messager.alert('提示信息', '请选中要打印的用户', 'info', function() {
    							
    						});
    					}else{
    						var unames = new Array();
    						var rnames = new Array();
    						$.each(checked,function(i,n){
    							unames[i] = n.uname;
    							rnames[i] = n.rname;
    						});
    						var msg = "您确认要打印用户信息吗?<br />";
    						$.messager.prompt('消息提示', msg+"打印后将保存在桌面上<br><br>请输入打印文件名!(如果不输入则系统自动默认))", function(r){
    							if (!r){
    								var date = new Date();
    								r = "";
    								r += date.getFullYear();
    								r += date.getMonth()+1;
    								r += date.getDate();
    								r += date.getHours();
    								r += date.getMinutes();
    								r += date.getMilliseconds();
    							}
    							$.ajax({
    						    	url:'printUserMsg',//打印选中的用户信息
    						    	type:'post',
    						    	data:{
    						    		unames:unames,
    						    		rnames:rnames,
    						    		file:r
    						    	},
    						    	dataType:'text',
    						    	success:function(data){
    						    		var data = eval('('+data+')');
    						    		if (data.success) {
    										$.messager.alert('提示信息', data.msg, 'info', function() {
    											$('#dg').datagrid('reload');
    										});
    									} else {
    										$.messager.alert('提示信息', data.msg, 'info', function() {
    											$('#dg').datagrid('reload');
    										});
    									}
    						    	}
    						    });
    						});
    					}
    				}
    			},'-',{
    				iconCls: 'icon-no',
    				text:'取消打印',
    				handler: function(){
    					$('#printWin').window('close');
    				}
    			}],
    			columns:[[
    				{field:'ck',checkbox:true,align:'center'},
    				{field:'uname',title:'Code',width:'48%',align:'center',halign:'center'},    
    				{field:'rname',title:'Name',width:'48%',align:'center',halign:'center'}
    			]]
    		}); 
    	})
</script>
<body>
   
   <div id="win" class="easyui-window" title="角色分配" style="width:600px;height:400px"align="center"   
        data-options="modal:true"> 
         
        <br/>
        <br/> 
        <input id="cc" name="dept"  />
        <br/>  
        <a id="xiugai" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'"style="margin-top:20px;">确认修改</a>
        <a id="quxiao" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'"style="margin-top:20px;">取消修改</a>  
</div> 
	
	
	


	<table class="easyui-layout"  id="dg" style="width:100%;">

		<a id="btn" href="#">点击更改角色</a>
	</table>

<div id="printWin"><!-- 打印用户窗口 -->
			<table id="printDg"></table><!-- 打印预览表格 -->
		</div>
</body>
</html>